package com.ruoyi.trainingManagement.domain.Vo;

import lombok.Data;

import java.io.Serializable;
import java.util.Objects;
/**
 * 课程排课基因视图对象 - 用于前端展示和数据传输
 */
@Data
public class ScheduleGeneVO implements Serializable {
    private static final long serialVersionUID = 1L;

    // 基本信息
    private String courseClassId;     // 课程班ID
    private String teacherId;         // 教师ID
    private Integer courseType;       // 课程类型
    private Integer teachingMode;     // 教学方式
    private Integer campus;           // 校区（数字编码）
    private Integer weekType;         // 周频次
    private Integer lessonCount;      // 单次节数
    private Integer startWeek;        // 开始周
    private Integer endWeek;          // 结束周
    private Integer maxCapacity;      // 最大容量
    private Integer currentEnrollment;// 当前选课人数
    private Integer schedulePriority; // 排课优先级

    // 排课结果
    private Integer dayOfWeek;        // 周几（数字：1-7对应周一至周日）
    private Integer startTimeSlot;    // 开始节次
    private Integer endTimeSlot;      // 结束节次
    private String classroomId;       // 教室ID
    private String building;          // 教学楼
    private String floor;             // 楼层
    private String classroomType;     // 教室类型

    // 计算属性
    private boolean isConflict;       // 是否冲突
    private double fitness;           // 适应度值
    private String fitnessLevel;      // 适应度等级（文本描述）

    // 构造函数：从基础数据初始化
    public ScheduleGeneVO() {
    }

    /**
     * 格式化显示字段（如适应度等级、时间段描述等）
     * 调用时机：属性赋值后、排课结果更新后
     */
    public void formatDisplayFields() {
        // 计算适应度等级
        if (fitness > 0.9) {
            fitnessLevel = "优";
        } else if (fitness > 0.7) {
            fitnessLevel = "良";
        } else if (fitness > 0.5) {
            fitnessLevel = "中";
        } else {
            fitnessLevel = "差";
        }

        // 自动计算结束节次（如果未设置）
        if (startTimeSlot != null && endTimeSlot == null && lessonCount != null) {
            endTimeSlot = startTimeSlot + lessonCount - 1;
        }
    }

    /**
     * 检查并标记冲突
     * @param conflictType 冲突类型（1-时间冲突，2-教室冲突，3-教师冲突）
     */
    public void markConflict(int conflictType) {
        this.isConflict = true;
        // 可根据需要扩展冲突详情描述
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        ScheduleGeneVO that = (ScheduleGeneVO) o;
        return isConflict == that.isConflict &&
                Double.compare(that.fitness, fitness) == 0 &&
                Objects.equals(courseClassId, that.courseClassId) &&
                Objects.equals(teacherId, that.teacherId) &&
                Objects.equals(courseType, that.courseType) &&
                Objects.equals(teachingMode, that.teachingMode) &&
                Objects.equals(campus, that.campus) &&
                Objects.equals(weekType, that.weekType) &&
                Objects.equals(lessonCount, that.lessonCount) &&
                Objects.equals(startWeek, that.startWeek) &&
                Objects.equals(endWeek, that.endWeek) &&
                Objects.equals(maxCapacity, that.maxCapacity) &&
                Objects.equals(currentEnrollment, that.currentEnrollment) &&
                Objects.equals(schedulePriority, that.schedulePriority) &&
                Objects.equals(dayOfWeek, that.dayOfWeek) &&
                Objects.equals(startTimeSlot, that.startTimeSlot) &&
                Objects.equals(endTimeSlot, that.endTimeSlot) &&
                Objects.equals(classroomId, that.classroomId) &&
                Objects.equals(building, that.building) &&
                Objects.equals(floor, that.floor) &&
                Objects.equals(classroomType, that.classroomType) &&
                Objects.equals(fitnessLevel, that.fitnessLevel);
    }

    @Override
    public int hashCode() {
        return Objects.hash(courseClassId, teacherId, courseType, teachingMode, campus, weekType, lessonCount,
                startWeek, endWeek, maxCapacity, currentEnrollment, schedulePriority, dayOfWeek, startTimeSlot,
                endTimeSlot, classroomId, building, floor, classroomType, isConflict, fitness, fitnessLevel);
    }

    @Override
    public String toString() {
        return "ScheduleGeneVO{" +
                "courseClassId='" + courseClassId + '\'' +
                ", dayOfWeek=" + dayOfWeek +
                ", startTimeSlot=" + startTimeSlot +
                ", endTimeSlot=" + endTimeSlot +
                ", classroomId='" + classroomId + '\'' +
                ", isConflict=" + isConflict +
                ", fitness=" + fitness +
                ", fitnessLevel='" + fitnessLevel + '\'' +
                '}';
    }
}